#ifndef DEBUGWINDOW_H
#define DEBUGWINDOW_H

#include <QMainWindow>

#include "conversationmodel.h"
#include "conversationdelegate.h"
#include "portmodel.h"
#include "serialport/serialserver.h"

namespace Ui {
class DebugWindow;
}

class DebugWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit DebugWindow(QWidget *parent = nullptr);
    virtual ~DebugWindow();

private:
    Ui::DebugWindow *ui;

private:
    ConversationModel mConversationModel;
    ConversationDelegate mConversationDelegate;
    PortModel mPortModel;

    SerialServer* mpSerialServer;

    int mRadioStatus;

    void onPortLoaded(QList<QSerialPortInfo>& ports);
    void updateUi();

    void onSendClicked();
    void onConnectClicked();
    void onClearClicked();

    void onRadioLoopback();
    void onRadioSendLora();
    void onRadioSetDeviceId();
    void onRadioGetDeviceId();

    void onSendLoopback(QByteArray& bytes);
    void onSendLora(QByteArray& bytes);
    void onSendSetDevice(QByteArray& bytes);
    void onSendGetDevice(QByteArray& bytes);

    void onRecvLora(QByteArray& bytes);
    void onRecvAckSendLora(QByteArray& bytes);
    void onRecvAckGetDeviceId(QByteArray& bytes);
    void onRecvAckSetDeviceId(QByteArray& bytes);
    void onRecvKeyEvent(QByteArray& bytes);
    void onRecvLog(QByteArray& bytes);
    void onRecvLoopback(QByteArray& bytes);
    void onRecvUnknown(QByteArray& bytes);

    QByteArray getInputText();
    static QByteArray parserInputText(QString& input);
    void onUsbReceived(QByteArray& bytes);

    static QString bytesToString(const QByteArray& bytes);
};

#endif // DEBUGWINDOW_H
